package com.fansea.util;


import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import org.apache.http.HttpResponse;
import org.apache.http.util.EntityUtils;

import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

public class SongUtil {



    public static void main(String[] args) {

        System.out.println(getAiMsg("林俊杰我怀恋的"));

    }

    public static HashMap getAiMsg(String msg) {
        HashMap<String, String> hashMap = new HashMap<>();
//        https://api.moonshot.cn/v1/chat/completions
        try {
            Map<String, String> headers = new HashMap<String, String>();
            headers.put("Content-Type","application/json");

            JSONObject myJsonObject = new JSONObject();
//        {
//            "model": "moonshot-v1-8k",
//                "messages": [
//            {"role": "system", "content": "你是 Kimi，由 Moonshot AI 提供的人工智能助手，你更擅长中文和英文的对话。你会为用户提供安全，有帮助，准确的回答。同时，你会拒绝一些涉及恐怖主义，种族歧视，黄色暴力等问题的回答。Moonshot AI 为专有名词，不可翻译成其他语言。"},
//            {"role": "user", "content": "你好，我叫李雷，1+1等于多少？"}
//    ],
//            "temperature": 0.3
//        }
//            https://music.163.com/api/search/get/web?csrf_token=hlpretag=&hlposttag=&s=%E6%88%91%E6%80%80%E6%81%8B%E7%9A%84%E6%9E%97%E4%BF%8A%E6%9D%B0&type=1&offset=0&total=true&limit=2

//            https://music.cyrilstudio.top/search?keywords=%E6%B5%B7%E9%98%94%E5%A4%A9%E7%A9%BA&limit=10
            HttpResponse httpResponse = AliHttpUtils.doGet("https://music.163.com/","/api/search/get/web?csrf_token=hlpretag=&hlposttag=&s=+"+URLEncoder.encode(msg, "UTF-8")+"+&type=1&offset=0&total=true&limit=2", "GET", headers,new HashMap<>());

            String weather = EntityUtils.toString(httpResponse.getEntity());
            JSONObject jsonObject = JSON.parseObject(weather);
            JSONObject result = jsonObject.getJSONObject("result");
            JSONArray songs = result.getJSONArray("songs");
            JSONObject jsonObject1 = songs.getJSONObject(0);
            String id = jsonObject1.getString("id");
            String name = jsonObject1.getString("name");
            JSONArray artists = jsonObject1.getJSONArray("artists");
            JSONObject jsonObject2 = artists.getJSONObject(0);
            String img1v1Url = jsonObject2.getString("img1v1Url");
            hashMap.put("id","https://music.cyrilstudio.top/song/url?id="+id+"");
            hashMap.put("name",name);
            hashMap.put("img1v1Url",img1v1Url);
            HttpRequestUtil.doGet("https://music.cyrilstudio.top/song/url?id="+id);
//        return JSONStringHandleUtil.getStats(wordJson,"content");
            //请求头
            String result2 = HttpRequestUtil.doGet("https://music.cyrilstudio.top/song/url?id="+id);
            JSONObject jsonObject3 = JSON.parseObject(result2);
            JSONArray data = jsonObject3.getJSONArray("data");
            JSONObject jsonObject4 = data.getJSONObject(0);
            String url = jsonObject4.getString("url");
            hashMap.put("id",url);

            https://music.cyrilstudio.top/song/url?id=440207933
            return hashMap;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return new HashMap();
    }




}
